﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class hg_view_revisions : CommonPage
    {
        int bugid;

        protected void Page_Load(object sender, EventArgs e)
        {
            Bug_Util.do_not_cache(Response);

            security = new Security();
            security.check_security(HttpContext.Current, Security.ANY_USER_OK);

            bugid = Convert.ToInt32(Bug_Util.sanitize_integer(Request["id"]));


            int permission_level = Bug.get_bug_permission_level(bugid, security);
            if (permission_level == Security.PERMISSION_NONE)
            {
                Response.Write("You are not allowed to view this item");
                Response.End();
            }

            titl.Text = Bug_Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                + "view hg file revisions";


            string sql = @"
select 
hgrev_revision [revision],
hgrev_repository [repo],
hgap_action [action],
hgap_path [file],
replace(replace(hgrev_author,'<','&lt;'),'>','&gt;') [user],
substring(hgrev_hg_date,1,19) [date],
replace(substring(hgrev_msg,1,4000),char(13),'<br>') [msg],

case when hgap_action not like '%D%' and hgap_action not like 'A%' then
	'<a target=_blank href=hg_diff.aspx?id=' + convert(varchar,hgap_id) + '>diff</a>'
	else
	''
end [view<br>diff],

case when hgap_action not like '%D%' then
'<a target=_blank href=hg_log.aspx?id=' + convert(varchar,hgap_id) + '>history</a>'
	else
	''
end [view<br>history<br>(hg log)]

from hg_revisions
inner join hg_affected_paths on hgap_hgrev_id = hgrev_id
where hgrev_bug = $bg
order by hgrev_hg_date desc, hgap_path";

            sql = sql.Replace("$bg", Convert.ToString(bugid));

            ds = DbUtil.get_dataset(sql);
        }
    }
}
